package cn.itsource.ymcc.feign.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

//转发token连接器
@Component
public class TokenInterceptor implements RequestInterceptor {
    //每个feign都会形成requestTemplate
    @Override
    public void apply(RequestTemplate requestTemplate) {

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        javax.servlet.http.HttpServletRequest request = requestAttributes.getRequest();
        if (request == null)return;
        //拿到token
        String header = request.getHeader("Authorization");
        //添加请求头
        RequestTemplate authorization = requestTemplate.header("Authorization", header);

    }
}
